#!/bin/bash

set -e

echo "Building AAR library..."

cd "$(dirname "$0")"

./gradlew clean
./gradlew assembleRelease

AAR_OUTPUT_DIR="output/aar"
mkdir -p "$AAR_OUTPUT_DIR"

AAR_FILE=$(find . -name "*.aar" -path "*/outputs/aar/*" | head -1)

if [ -n "$AAR_FILE" ]; then
    cp "$AAR_FILE" "$AAR_OUTPUT_DIR/"
    echo "✓ AAR built successfully: $AAR_OUTPUT_DIR/$(basename $AAR_FILE)"
else
    echo "✗ AAR file not found"
    exit 1
fi
